package com.ff.javamonkey.test.ui;

import com.ff.javamonkey.R;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class SummaryFragment extends ListFragment {
	// Debugging
	private static final String TAG = "SummaryFragment";
	
	private BaseAdapter mAdapter;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mAdapter = new SummaryAdapter(getActivity());
		
		setListAdapter(mAdapter);
	}
	
	private class SummaryAdapter extends BaseAdapter {
		private Context context;
		private ViewHolder viewHolder;
		
		public SummaryAdapter(Context context) {
			super();
			this.context = context;
		}		

		public int getCount() {
			// TODO Auto-generated method stub
			return 2;
		}

		public Object getItem(int position) {
			// TODO Auto-generated method stub
			if (position == 0) return "Musang";
			else return "Cerpelai";
		}

		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		public View getView(int position, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			if (convertView == null) {
				final LayoutInflater factory = LayoutInflater.from(context);
				convertView = factory.inflate(R.layout.list_test_summary_item, null);
				viewHolder = new ViewHolder();
				viewHolder.tv = (TextView)convertView.findViewById(R.id.txtTestSumamry);
				convertView.setTag(viewHolder);
			}
			else {
				viewHolder = (ViewHolder)convertView.getTag();
			}
			viewHolder.tv.setText(getItem(position).toString());
			return convertView;
		}
	}
	
	private static class ViewHolder {
		TextView tv;
	}
}
